import asyncio
import ctypes
import time

import win32api
import win32con





class Diablo:
    def __init__(self,hwnd):
        self.hwnd=hwnd
        self.vk_code_1 = 0x31
        self.vk_code_2 = 0x32
        self.vk_code_3 = 0x33
        self.vk_code_4 = 0x34
        self.vk_code_Q = 0x51
        self.vk_code_Space= 0x20

        self.MOUSEEVENTF_RIGHTDOWN = 0x0008
        self.MOUSEEVENTF_RIGHTUP = 0x0010

    def one(self):
        win32api.SendMessage(self.hwnd, win32con.WM_KEYDOWN, self.vk_code_1, 0)
        win32api.SendMessage(self.hwnd, win32con.WM_KEYUP, self.vk_code_1, 0)
    def two(self):
        win32api.SendMessage(self.hwnd, win32con.WM_KEYDOWN, self.vk_code_2, 0)
        win32api.SendMessage(self.hwnd, win32con.WM_KEYUP, self.vk_code_2, 0)

    def three(self):
        win32api.SendMessage(self.hwnd, win32con.WM_KEYDOWN, self.vk_code_3, 0)
        win32api.SendMessage(self.hwnd, win32con.WM_KEYUP, self.vk_code_3, 0)

    def four(self):
        win32api.SendMessage(self.hwnd, win32con.WM_KEYDOWN, self.vk_code_4, 0)
        win32api.SendMessage(self.hwnd, win32con.WM_KEYUP, self.vk_code_4, 0)
    def Q(self):
        win32api.SendMessage(self.hwnd, win32con.WM_KEYDOWN, self.vk_code_Q, 0)
        win32api.SendMessage(self.hwnd, win32con.WM_KEYUP, self.vk_code_Q, 0)

    def ButtonLetf(self):
        win32api.SendMessage(self.hwnd, win32con.WM_KEYDOWN, self.vk_code_Space, 0)
        win32api.SendMessage(self.hwnd, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON)
        win32api.SendMessage(self.hwnd, win32con.WM_LBUTTONUP, 0)
        win32api.SendMessage(self.hwnd, win32con.WM_KEYUP, self.vk_code_Space, 0)

    def click_at_current_position(self):
        # 获取当前鼠标位置
        x, y = win32api.GetCursorPos()

        # 将屏幕坐标转换为窗口坐标
        point = win32api.MAKELONG(x, y)

        # 发送鼠标按下消息 (WM_LBUTTONDOWN)
        win32api.SendMessage(self.hwnd, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, point)

        # # 短暂延迟（模拟真实点击）
        # time.sleep(0.05)
        #
        # # 发送鼠标释放消息 (WM_LBUTTONUP)
        # win32api.SendMessage(self.hwnd, win32con.WM_LBUTTONUP, 0, point)

    def ButtonRight(self):
        win32api.SendMessage(self.hwnd, win32con.WM_RBUTTONDOWN, win32con.MK_RBUTTON)
        win32api.SendMessage(self.hwnd, win32con.WM_RBUTTONUP, 0)


    def ButtonRightDown(self):
        ctypes.windll.user32.mouse_event(self.MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0)

    def ButtonRightUp(self):
        ctypes.windll.user32.mouse_event(self.MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0)
